"""
Assessment Plan 业务系统评估计划表模型
"""
import uuid
from datetime import datetime
from sqlalchemy import Column, String, Enum, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from db.base import Base

class AssessmentPlan(Base):
    """业务系统评估计划数据模型"""
    __tablename__ = "assessment_plan"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    name = Column(String(255), nullable=False, comment="业务系统名称")
    rating_filing_name = Column(String(255), nullable=False, comment="评级备案名称")
    responsible_person = Column(String(100), nullable=False, comment="负责人")
    business_department = Column(String(100), nullable=False, comment="业务部门")
    
    # Relationships
    compliance_items = relationship("ComplianceItem", back_populates="assessment_plan", cascade="all, delete-orphan")
    issues = relationship("ComplianceItemIssue", back_populates="assessment_plan", cascade="all, delete-orphan")
    contact = Column(String(50), nullable=False, comment="联系方式")
    assessment_type = Column(String(20), nullable=False, comment="评估类型")
    expected_completion_date = Column(DateTime(timezone=True), nullable=False, comment="预期完成日期")
    created_at = Column(DateTime(timezone=True), default=datetime.now, nullable=False, comment="创建时间")
    status = Column(Enum('in_progress', 'completed', name='system_status'), 
                   nullable=False, default='in_progress', comment="状态")
    template_id = Column(UUID(as_uuid=True), ForeignKey("compliance_template.id"), nullable=True, comment="评估计划使用的模版")

    # 关系定义
    compliance_items = relationship("ComplianceItem", back_populates="assessment_plan", cascade="all, delete-orphan")
    remediations = relationship("RemediationItem", back_populates="assessment_plan", cascade="all, delete-orphan")
    template = relationship("ComplianceTemplate", back_populates="assessment_plans")
    issues = relationship("ComplianceItemIssue", back_populates="assessment_plan", cascade="all, delete-orphan")